package com.woniuxy.amusementparkos.service.lsy.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.amusementparkos.dao.lsy.ConsumerItemDao;
import com.woniuxy.amusementparkos.entity.lsy.ConsumerItem;
import com.woniuxy.amusementparkos.exception.ObjectNotExistException;
import com.woniuxy.amusementparkos.service.lsy.ConsumerItemService;

/**
* @author Muzi
* 消费项服务对象
* 2020年4月26日下午8:20:37
*/
@Service
public class ConsumerItemServiceImpl implements ConsumerItemService {
	//注入dao接口，创建实现对象
	@Autowired
	private ConsumerItemDao consumerItemDao;
	
	//查询所有 消费项
	@Override
	public List<ConsumerItem> listAll() {
		return consumerItemDao.listAllConsumerItem();
	}

	//添加消费项
	@Override
	public void insertConsumerItem(ConsumerItem consumerItem) {
		consumerItemDao.insertConsumerItem(consumerItem);
	}

	//修改消费项
	@Override
	public void updateConsumerItem(ConsumerItem consumerItem) throws RuntimeException {
		Integer rows = consumerItemDao.updateOneConsumerItem(consumerItem);
		if(rows == 0) {
			throw new ObjectNotExistException("修改失败，目标不存在");
		}

	}
	
	//删除消费项
	@Override
	public void deleteConsumerItem(Integer consumer_item_id) throws RuntimeException {
		Integer rows = consumerItemDao.deleteOneConsumerItemByItemId(consumer_item_id);
		if(rows == 0) {
			throw new ObjectNotExistException("删除失败，目标不存在");
		}
	}

}
